package com.yaoben.exam.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.yaoben.exam.dao.UserMapper;
import com.yaoben.exam.pojo.User;
import com.yaoben.exam.service.UserService;

@Service("userServiceImpl")
public class UserServiceImpl implements UserService{

	@Autowired
	private UserMapper userMapper;
	@Override
	public User getUserById(int id) {
		return userMapper.selectByPrimaryKey(id);
	}

	@Override
	public User getUserByLoginName(String loginname) {
		return userMapper.selectByLoginName(loginname);
	}

	@Override
	public int add(User user) {
		return userMapper.insertSelective(user);
	}

	@Override
	public int updateUserById(User user) {
		return userMapper.updateByPrimaryKeySelective(user);
	}

	@Override
	public int addOrUpdateUser(User user) {
		if(user.getId()==0){
			return userMapper.insertSelective(user);
		}else{
			return userMapper.updateByPrimaryKeySelective(user);
		}
	}
	@Override
	public int deleteUserById(Integer id) {
		return userMapper.deleteByPrimaryKey(id);
	}

}
